#
#  Copyright 2022 The Open Islands Authors. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
import typing

from .runtime_config import RuntimeConfig
from .operator_input import OperatorInput
from .operator_output import OperatorOutput
from pyoi.types import BaseType


class RunArgs(BaseType):
    def __init__(self):
        self.job_type = ""
        self.entry_point: str = ""
        self.role: str = ""
        self.node_id: str = ""
        self.nodes: typing.Dict[str, typing.List[str]] = {}
        self.input: OperatorInput = None
        self.output: OperatorOutput = None
        self.params: dict = {}

    @classmethod
    def from_runtime_config(cls, runtime_config: RuntimeConfig):
        args = RunArgs()
        args.job_type = runtime_config.jobType
        args.entry_point = runtime_config.entryPoint
        args.role = runtime_config.role
        args.node_id = runtime_config.nodeId
        args.nodes = runtime_config.nodes
        args.input = runtime_config.input
        args.output = runtime_config.output
        args.params = runtime_config.operatorParams
        return args
